# Contributor: Fabian Affolter <fabian@affolter-engineering.ch>
# Maintainer: Fabian Affolter <fabian@affolter-engineering.ch>
pkgname=makepasswd
pkgver=0.5.4
pkgrel=1
pkgdesc="Generates (pseudo-)random passwords of a desired length"
url="https://www.defora.org/os/project/117/makepasswd"
arch="all"
license="GPL-3.0"
makedepends="libxslt docbook-xsl openssl1.1-compat-dev"
subpackages="$pkgname-doc"
source="https://www.defora.org/os/download/download/4438/$pkgname-$pkgver.tar.gz"

build() {
	make
	make -C doc
}

package() {
	install -D -p -m 755 src/makepasswd "$pkgdir"/usr/bin/makepasswd
	install -D -p -m 644 doc/makepasswd.1 \
		"$pkgdir"/usr/share/man/man1/$pkgname.1
}

check() {
	local expected output

	# Generated expected hash with:
	# {
	#  printf -- '%s  %s\n' testing "$(printf testing | openssl enc -a)" ;
	#  printf testing | openssl dgst -md5 | awk '{$1="testing "; print; quit;}' ;
	#  for a in des md5 sha256 ; do printf -- '%s  ' testing; mkpasswd -m "$a" testing foobar ; done ;
	# } | sha512sum
	#
	expected='11d0cc3117bb6074adefaded0ed5f2a50fdc6b5448d832dd25b742edb499f225fe2469f7ae7f8859921640f2f31c62d6b2c82d7ea9471fb28a152a011aac7406'
	output="$(mktemp -q -p .)"

	local a; for a in base64 md5 des shmd5 sha256; do
		./src/makepasswd -e "$a" -s 'foobar' -p 'testing'
	done > "$output"

	printf -- '%s  %s\n' "$expected" "$output" | sha512sum -c
}

sha512sums="c8721826c7329b2c4e7fc2226e31a081347b66a76827ca669547125fed2175035ecd6b7d46aacdf8ae6ee140281caf31e5bdbecdd2807723800596fd0140aaa0  makepasswd-0.5.4.tar.gz"
